<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="h-ui-font/iconfont.min.css" />
		<link rel="stylesheet" type="text/css" href="css/jquery-weui.min.css" />
		<link rel="stylesheet" type="text/css" href="css/weui.min.css" />
		<script src="js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/vue(1).js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			* {
				margin: 0px;
				padding: 0px;
			}
			
			body {
				width: 100%;
				background-color: #F5F5F5;
			}
			
			.top {
				width: 320px;
				height: 150px;
				font-size: 50px;
				color: #0F88EB;
				font-weight: bold;
				line-height: 150px;
				text-align: center;
			}
			
			.weui-tab {
				width: 320px;
				height: 320px;
			}
			
			.weui-navbar a {
				font-weight: bold;
				font-size: 20px !important;
			}
			
			.weui-bar__item--on {
				color: #0F88EB !important;
			}
			
			.weui-label {
				width: 80px;
				text-align: center;
				font-size: 16px;
			}
			
			.weui-cell {
				font-size: 12px;
			}
			
			.all {
				width: 320px;
				height: 460px;
				position: absolute;
				top: 0px;
				bottom: 0px;
				left: 0px;
				right: 0px;
				margin: auto;
			}
			
			.weui-tab__bd a {
				margin-top: 20px;
			}
		</style>
	</head>

	<body>
		<div class="all">
			<div class="top">知乎</div>
			<div class="weui-tab">
				<div class="weui-navbar">
					<a class="weui-navbar__item weui-bar__item--on" href="#tab1">注册</a>
					<a class="weui-navbar__item" href="#tab2">登录</a>
				</div>

				<div class="weui-tab__bd">
					<div id="tab1" class="weui-tab__bd-item weui-tab__bd-item--active">
						<div class="weui-cells weui-cells_form">
							<div class="weui-cell">
								<div class="weui-cell__hd"><label class="weui-label dengluming" >登录名</label></div>
								<div class="weui-cell__bd">
									<input class="weui-input" type="text" pattern="[0-9]*" placeholder="请输入登录名（不少于4位）" v-model="dengluming">
								</div>
							</div>
							<div class="weui-cell">
								<div class="weui-cell__hd"><label class="weui-label nicheng" >昵称</label></div>
								<div class="weui-cell__bd">
									<input class="weui-input" type="text" pattern="[0-9]*" placeholder="请输入昵称（不少于4位）" v-model="nicheng">
								</div>
							</div>
							<div class="weui-cell">
								<div class="weui-cell__hd"><label class="weui-label youxiang" >邮箱</label></div>
								<div class="weui-cell__bd">
									<input class="weui-input" type="text" pattern="[0-9]*" placeholder="请输入邮箱" v-model="youxiang">
								</div>
							</div>
							<div class="weui-cell">
								<div class="weui-cell__hd"><label class="weui-label mima" >密码</label></div>
								<div class="weui-cell__bd">
									<input class="weui-input" type="password" pattern="[0-9]*" placeholder="请输入密码（不少于6位小写字母和数字）" v-model="mima">
								</div>
							</div>

						</div>
						<a href="javascript:;" class="weui-btn weui-btn_primary zhuce" v-on:click="yanzheng()">注册</a>
					</div>
					<div id="tab2" class="weui-tab__bd-item">
						<div class="weui-cells weui-cells_form">
							<div class="weui-cell">
								<div class="weui-cell__hd"><label class="weui-label" >登录名</label></div>
								<div class="weui-cell__bd">
									<input class="weui-input" type="text" pattern="[0-9]*" placeholder="请输入登录名" v-model="loginname">
								</div>
							</div>
							<div class="weui-cell">
								<div class="weui-cell__hd"><label class="weui-label">密码</label></div>
								<div class="weui-cell__bd">
									<input class="weui-input" type="password" pattern="[0-9]*" placeholder="请输入密码" v-model="loginpwd">
								</div>
							</div>
							<div class="weui-cell weui-cell_vcode">
								<div class="weui-cell__hd"><label class="weui-label" >验证码</label></div>
								<div class="weui-cell__bd">
									<input class="weui-input" type="text" placeholder="请输入验证码" v-model="yanzhengma">
								</div>
								<div class="weui-cell__ft">
									<img class="weui-vcode-img" src="./images/vcode.jpg">
								</div>
							</div>
						</div>
						<a href="javascript:;" class="weui-btn weui-btn_primary denglu" v-on:click="login()">登录</a>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			var ss;
			var dd;
			var vue = new Vue({
				el: "body",
				data: {
					dengluming: "",
					nicheng: "",
					youxiang: "",
					mima: "",
					loginname: "",
					loginpwd: "",
					yanzhengma: "",
					loginid:""
				},
				methods: {
					yanzheng:function(){
						var registname=new RegExp(/^[a-z0-9_-]{3,16}$/).test(vue.dengluming);
						var nicheng=new RegExp(/^[a-z0-9_-]{3,16}$/).test(vue.nicheng);
						var youxiang=new RegExp(/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/).test(vue.youxiang);
						var nicheng=new RegExp(/^[a-z0-9_-]{6,18}$/).test(vue.nicheng);
						if(registname&&nicheng&&youxiang&&nicheng){
							vue.reg(ss,dd);
						}else{
							alert("请输入正确的信息")
						}
					},
					auth: function() {
						$.ajax({
							type: 'get',
							//async:false,
							url: "http://v2.mashupcloud.cn/developer/auth.do",
							data: {
								appkey: 'FvWrIYOQoTUYVbscUNQoQAVqsLnZqKEN',
								appsecret: 'ugCfcSmyLkcbCGfIuFOPEgTgPQPbyJSE'

							},
							success: function(json) {
								//		            console.log(json);
								ss = JSON.parse(json)[1];
								dd = JSON.parse(json)[2];
								sessionStorage.setItem("appid",dd);
								sessionStorage.setItem("token",ss);
							},
							error: function(json) {

								console.log("err:" + json);

							}
						});
					},
					reg: function(ss, dd) {
						$.ajax({
							type: 'get',
							url: "http://v2.mashupcloud.cn/SQL/reg_user/",
							data: {
								appid: dd,
								token: ss,
								name: 'reg_user',
								_v1: vue.dengluming,
								_v2: vue.mima,
								_v3: vue.nicheng,
								_v4: vue.youxiang
							},
							success: function(json) {
								console.log("json==" + json);
								
							},
							error: function(json) {
								console.log("err:" + json);

							}
						});

					},
					login: function() {
						$.ajax({
							type: 'get',
							url: "http://v2.mashupcloud.cn/SQL/sele_user_dl/",
							data: {
								appid: dd,
								token: ss,
								name: 'sele_user_dl',
								_v1: vue.loginname,
								_v2: vue.loginpwd,
								
							},
							success: function(json) {
								console.log("json==" + json);
								var json1=JSON.parse(json);
								if(json1[2].length!=0){
									sessionStorage.setItem("username",vue.loginname);
									sessionStorage.setItem("userid",json1[2][0].id);
									history.back();
									console.log("有该用户")
								}else{
									alert("用户名或密码错误");
								}
							},
							error: function(json) {
								console.log("err:" + json);
							    console.log("没有该用户")
							}
						});

					},
					

				}
			});
			vue.auth();
		</script>
	</body>

</html>